home *** CD-ROM | disk | FTP | other *** search
/ MACD 5 / MACD 5.bin / polski_aminet / miroslaw_siedlarz / bcc / examples / joytest / app.bc next >
Text File  |  1997-06-22  |  7KB  |  261 lines

  1. #include <proto/dos.h>
  2. #include <proto/lowlevel.h>
  3. #include <intuition/imageclass.h>
  4.  
  5. #include "App.bh"
  6. #include "EJG.h"
  7.  
  8. void myputch( void );
  9.  
  10. static const char *centr[] = {
  11.     "Port 1 (mouse)",
  12.     "Port 2 (game)",
  13.     NULL
  14. };
  15.  
  16. cleardata Method App::App() :
  17.         MUIA_Application_Author, "Rafaî Mantiuk",
  18.         MUIA_Application_Base, "JOYTEST",
  19.         MUIA_Application_Title, "JoyTest",
  20.         MUIA_Application_Version, "$VER: JOYTEST 1.0 "__AMIGADATE__,
  21.         MUIA_Application_Copyright, "Copyright (c)1997, Rafaî Mantiuk",
  22.         MUIA_Application_Description, "Joystick test.",
  23.         SubWindow, win = WindowObject,
  24.             MUIA_Window_Title, "Joystick test v1.0",
  25.             MUIA_Window_ID, MAKE_ID('M', 'A', 'I', 'N'),
  26.             WindowContents, GroupObject,
  27.                 MUIA_Background, MUII_WindowBack,
  28.                 MUIA_Group_Horiz, TRUE,
  29.                 Child, GroupObject, 
  30.                     Child, cycle = CycleObject,
  31.                         MUIA_Cycle_Entries, centr,
  32.                         MUIA_Cycle_Active, 1,        
  33.                         MUIA_CycleChain, TRUE,
  34.                         MUIA_Background, MUII_TextBack,
  35.                     End,
  36.                     Child, inf = TextObject,
  37.                         MUIA_Background, MUII_TextBack,
  38.                     End,
  39.                     Child, HVSpace,
  40.                     Child, GroupObject,
  41.                         MUIA_Group_Columns, 3,
  42.                         Child, HVSpace,
  43.                         Child, up = ImageObject,
  44.                             MUIA_Image_Spec, "6:11",
  45.                             MUIA_Frame, MUIV_Frame_InputList,
  46.                             MUIA_Image_FontMatch, TRUE,
  47.                             MUIA_Background, MUII_ButtonBack,
  48.                         End,
  49.                         Child, HVSpace,
  50.                         Child, left = ImageObject,
  51.                             MUIA_Image_Spec, "6:13",
  52.                             MUIA_Frame, MUIV_Frame_InputList,
  53.                             MUIA_Image_FontMatch, TRUE,
  54.                             MUIA_Background, MUII_ButtonBack,
  55.                         End,
  56.                         Child, HGroup,
  57.                             Child, trig = ImageObject,
  58.                                 MUIA_Image_Spec, "6:16",
  59.                                 MUIA_Frame, MUIV_Frame_InputList,
  60.                                 MUIA_Image_FontMatch, TRUE,
  61.                                 MUIA_Background, MUII_ButtonBack,
  62.                                 MUIA_ShortHelp, "First fire button",
  63.                             End,
  64.                             Child, strig = TextObject,
  65.                                 MUIA_Frame, MUIV_Frame_InputList,
  66.                                 MUIA_Background, MUII_ButtonBack,
  67.                                 MUIA_Text_Contents, "2nd",
  68.                                 MUIA_ShortHelp, "Second fire button",
  69.                             End,
  70.                         End,
  71.                         Child, right = ImageObject,
  72.                             MUIA_Image_Spec, "6:14",
  73.                             MUIA_Frame, MUIV_Frame_InputList,
  74.                             MUIA_Image_FontMatch, TRUE,
  75.                             MUIA_Background, MUII_ButtonBack,
  76.                         End,
  77.                         Child, HVSpace,
  78.                         Child, down = ImageObject,
  79.                             MUIA_Image_Spec, "6:12",
  80.                             MUIA_Frame, MUIV_Frame_InputList,
  81.                             MUIA_Image_FontMatch, TRUE,
  82.                             MUIA_Background, MUII_ButtonBack,
  83.                         End,
  84.                         Child, HVSpace,
  85.                     End,
  86.                     Child, HVSpace,
  87.                     Child, dval = TextObject,
  88.                         MUIA_Background, MUII_TextBack,
  89.                         MUIA_Text_PreParse, "\33c",
  90.                         MUIA_ShortHelp, "Value returned by\nlowlevel.library/ReadJoyPort()",
  91.                     End,
  92.                 End,
  93.                 Child, BalanceObject,
  94.                 End,
  95.                 Child, GroupObject, 
  96.                     MUIA_Group_Columns, 2,
  97.                     Child, lup = ImageObject,
  98.                         MUIA_Image_Spec, "6:11",
  99.                         MUIA_Frame, MUIV_Frame_InputList,
  100.                         MUIA_Image_FontMatch, TRUE,
  101.                         MUIA_Background, MUII_ButtonBack,
  102.                     End,
  103.                     Child, EJGup = EJGObject,
  104.                     End,
  105.                     Child, ldown = ImageObject,
  106.                         MUIA_Image_Spec, "6:12",
  107.                         MUIA_Frame, MUIV_Frame_InputList,
  108.                         MUIA_Image_FontMatch, TRUE,
  109.                         MUIA_Background, MUII_ButtonBack,
  110.                     End,
  111.                     Child, EJGdown = EJGObject,
  112.                     End,
  113.                     Child, lleft = ImageObject,
  114.                         MUIA_Image_Spec, "6:13",
  115.                         MUIA_Frame, MUIV_Frame_InputList,
  116.                         MUIA_Image_FontMatch, TRUE,
  117.                         MUIA_Background, MUII_ButtonBack,
  118.                     End,
  119.                     Child, EJGleft = EJGObject,
  120.                     End,
  121.                     Child, lright =ImageObject,
  122.                         MUIA_Image_Spec, "6:14",
  123.                         MUIA_Frame, MUIV_Frame_InputList,
  124.                         MUIA_Image_FontMatch, TRUE,
  125.                         MUIA_Background, MUII_ButtonBack,
  126.                     End,
  127.                     Child, EJGright = EJGObject,
  128.                     End,
  129.                     Child, ltrig = ImageObject,
  130.                         MUIA_Image_Spec, "6:16",
  131.                         MUIA_Frame, MUIV_Frame_InputList,
  132.                         MUIA_Image_FontMatch, TRUE,
  133.                         MUIA_Background, MUII_ButtonBack,
  134.                         MUIA_ShortHelp, "First fire button",
  135.                     End,
  136.                     Child, EJGtrig = EJGObject,
  137.                     End,
  138.                     Child, lstrig = TextObject,
  139.                         MUIA_Frame, MUIV_Frame_InputList,
  140.                         MUIA_Background, MUII_ButtonBack,
  141.                         MUIA_Text_Contents, "2nd",
  142.                         MUIA_ShortHelp, "Second fire button",
  143.                     End,
  144.                     Child, EJGstrig = EJGObject,
  145.                     End,
  146.                 End,
  147.             End,
  148.         End
  149. {
  150.  
  151.     win->_Notify( 
  152.         MUIA_Window_CloseRequest, TRUE,
  153.         obj, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit );
  154.     left->_Notify(
  155.         MUIA_Image_State, MUIV_EveryTime,
  156.         lleft, 3, MUIM_Set, MUIA_Image_State, MUIV_TriggerValue );
  157.     right->_Notify(
  158.         MUIA_Image_State, MUIV_EveryTime,
  159.         lright, 3, MUIM_Set, MUIA_Image_State, MUIV_TriggerValue );
  160.     up->_Notify(
  161.         MUIA_Image_State, MUIV_EveryTime,
  162.         lup, 3, MUIM_Set, MUIA_Image_State, MUIV_TriggerValue );
  163.     down->_Notify(
  164.         MUIA_Image_State, MUIV_EveryTime,
  165.         ldown, 3, MUIM_Set, MUIA_Image_State, MUIV_TriggerValue );
  166.     trig->_Notify(
  167.         MUIA_Image_State, MUIV_EveryTime,
  168.         ltrig, 3, MUIM_Set, MUIA_Image_State, MUIV_TriggerValue );
  169.     strig->_Notify(
  170.         MUIA_Selected, MUIV_EveryTime,
  171.         lstrig, 3, MUIM_Set, MUIA_Selected, MUIV_TriggerValue );
  172.  
  173.     win->Open = TRUE;
  174.  
  175. }
  176.  
  177. Attribute Set App::State( long value )
  178. {
  179.  ULONG v, x;
  180.  STRPTR cont;
  181.  v = value  & JP_DIRECTION_MASK;
  182.  
  183.  
  184.     if( value != lastval ) {
  185.         RawDoFmt( "$%lx", (ULONG*)&value, myputch, txbuf );
  186.         dval->Contents = txbuf;
  187.     }
  188.     lastval = value;
  189.  
  190.     switch( value & JP_TYPE_MASK ) {
  191.         case JP_TYPE_JOYSTK:
  192.             cont = "Joystick detected";
  193.             break;
  194.         case JP_TYPE_MOUSE:
  195.             cont = "Mouse detected";
  196.             break;
  197.         case JP_TYPE_GAMECTLR:
  198.             cont = "Game controller detected";
  199.             break;
  200.         default:
  201.             cont = "Unknown device";
  202.     }
  203.     if( lastcont != cont ) {
  204.         inf->Contents = cont;
  205.     }
  206.     lastcont = cont;
  207.  
  208.  
  209.     if( ( value & JP_TYPE_MASK ) == JP_TYPE_JOYSTK ) {
  210.  
  211.     if( v & JPF_JOY_UP ) {
  212.         up->State = IDS_SELECTED;
  213.         EJGup->Anim( 1 );
  214.     }
  215.     else {
  216.         up->State = IDS_NORMAL;
  217.         EJGup->Anim( 0 );
  218.     }
  219.     if( v & JPF_JOY_DOWN ) {
  220.         down->State = IDS_SELECTED;
  221.         EJGdown->Anim( 1 );
  222.     }
  223.     else {
  224.         down->State = IDS_NORMAL;
  225.         EJGdown->Anim( 0 );
  226.     }
  227.     if( v & JPF_JOY_LEFT ) {
  228.         left->State = IDS_SELECTED;
  229.         EJGleft->Anim( 1 );
  230.     }
  231.     else {
  232.         left->State = IDS_NORMAL;
  233.         EJGleft->Anim( 0 );
  234.     }
  235.     if( v & JPF_JOY_RIGHT ) {
  236.         right->State = IDS_SELECTED;
  237.         EJGright->Anim( 1 );
  238.     }
  239.     else {
  240.         right->State = IDS_NORMAL;
  241.         EJGright->Anim( 0 );
  242.     }
  243.  
  244.     x = value & JPF_BUTTON_RED ? 1 : 0;
  245.     trig->State =  x ? IDS_SELECTED : IDS_NORMAL;
  246.     EJGtrig->Anim( x );
  247.  
  248.     x = value & JPF_BUTTON_BLUE ? 1 : 0;
  249.     strig->_Selected =  x;
  250.     EJGstrig->Anim( x );
  251.  
  252.  
  253.     }
  254.  
  255. }
  256.  
  257. Attribute Get App::Port( ULONG *store )
  258. {
  259.     *store = cycle->Active;
  260. }
  261.